<!--
 * @Description: 项目经理月报评价
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-04-07 16:07:49
 * @LastEditTime: 2022-04-19 18:06:58
 * @FilePath: \cscec-pms-admin\src\views\project\projectManagerMonthlyReportEvaluate\index.vue
-->
<template>
  <base-breadcrumb>
    <a-row :gutter="10">
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }">
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <!-- 树搜索 -->
      <!-- 列表 -->
      <a-col
        :span="18"
        class="permission-collapsed"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <a-card>
          <!-- <title-name title="项目经理月报评价" /> -->
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">
              总数量：<span class="totalNum">{{ totalSize }}</span> 个
            </span>
          </div>
          <list-table
            ref="table"
            row-key="id"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
          >
            <template
              slot="operation"
              slot-scope="text, record"
            >
              <MoreButton>
                <a
                  v-btnPermission="'pm_058_loo_01'"
                  @click="handleOperation('detail',record)"
                >查看</a>
                <a
                  v-if="record.evaluationStatus === 1"
                  v-btnPermission="'pm_058_exp_02'"
                  :href="'/api/face-producer-server/projectManagerMonthlyReportEvaluation/exportWord?access_token=' + token + '&id=' + record.id"
                  target="_parent"
                >导出</a>
                <a @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批信息</a>
              </MoreButton>
            </template>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>
<script>
import { searchOption, columns } from './model.js'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
import MoreButton from '@/components/MoreButton'
import { list } from '@/api/project/projectManagerMonthlyReportEvaluate'
import Vue from 'vue'
export default {
  name: 'projectManagerMonthlyReportEvaluate' + Date.now(),
  components: {
    PermissionTreeOrganization,
    MoreButton
  },
  data() {
    return {
      // 令牌
      token: Vue.getAcloudProvider().getAccessToken(),
      // 收缩展开树
      collapsed: false,
      // 树选中项
      select: {},
      // 查询参数
      searchData: {},
      // 搜索选项
      searchOption,
      //表头
      columns,
      // 总数
      totalSize: 0
    }
  },
  methods: {
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 搜索
     * @param {object} value 搜索数据
     * @return {void}
     */
    search(value) {
      this.searchData = value || {}
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 表格数据加载方法
     * @param {Object} parameter 分页信息
     * @return {Promise} 接口Promise
     */
    async loadData(parameter) {
      try {
        // 树选中
        if (Object.keys(this.select).length > 0) {
          let branchComId = undefined
          if (this.select.tageCode === 'BC') {
            branchComId = this.select.orgId
          }
          let projectId = this.select.projectId || undefined
          const { pmName, reportMonthlyStartTime, reportMonthlyEndTime, branchCom, company } = this.searchData
          const searchData = {
            pageNum: parameter.pageNo,
            pageSize: parameter.pageSize,
            param: {
              branchComId,
              projectId,
              pmName,
              reportMonthlyStartTime,
              reportMonthlyEndTime,
              branchComStartScore: branchCom?.split('-')[0],
              branchComEndScore: branchCom?.split('-')[1],
              companyStartScore: company?.split('-')[0],
              companyEndScore: company?.split('-')[1]
            }
          }
          const res = await list.getPageMonthlyReportEvaluationBySearch(searchData)
          if (res.code === 200) {
            this.totalSize = res.totalSize
            return Promise.resolve(res)
          } else {
            return Promise.reject()
          }
        } else {
          return Promise.reject()
        }
      } catch (error) {
        console.log(error)
        return Promise.reject()
      }
    },
    /**
     * @description: 操作
     * @param {string} pageType 操作类型
     * @param {object} record 行数据
     * @return {void}
     */
    handleOperation(pageType, record) {
      const { id } = record
      this.$router.push({
        path: '/project/projectManagerMonthlyReportEvaluateView',
        query: {
          pageType,
          id
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
